package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.DFood;
import com.tour.service.impl.DFoodServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-03-30
 */
@RestController
@Api(tags = "美食管理")
public class DFoodController {

    @Autowired
    DFoodServiceImpl foodService;

    @ApiOperation("增加美食")
    @PostMapping("/addfood")
    public ResponseWrapper addFood(@RequestBody DFood food){
        ResponseWrapper wrapper = foodService.addFood(food);
        return wrapper;
    }
    @ApiOperation("删除某个美食")
    @DeleteMapping("/deletefood")
    @ApiImplicitParam(name = "fid",value = "美食id")
    public ResponseWrapper deleteFood(Integer fid){
        ResponseWrapper wrapper = foodService.deleteFood(fid);
        return wrapper;
    }
    @ApiOperation("修改某个美食")
    @PutMapping("/updateFood")
    public ResponseWrapper updateFood(@RequestBody DFood food){
        ResponseWrapper wrapper = foodService.updateFood(food);
        return wrapper;
    }
    @ApiOperation("查看某一个美食")
    @GetMapping("/app/findFood")
    @ApiImplicitParam(name = "fid",value = "美食id")
    public ResponseWrapper findFood(Integer fid){
        ResponseWrapper wrapper = foodService.findFood(fid);
        return wrapper;
    }

    @ApiOperation("查看所有美食或者模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "name",value = "餐厅名字"),
            @ApiImplicitParam(name = "flavor",value = "口味")
    })
    @GetMapping("/app/findAllfood")
    public ResponseWrapper findAllfood(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(name = "name",required = false)String name,
                                       @RequestParam(name = "flavor",required = false)String flavor){
        ResponseWrapper wrapper = foodService.findAllfood(name,pageSize,pageNum,flavor);
        return wrapper;
    }

}

